<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:tr="http://myfaces.apache.org/trinidad"
        >

<f:view>

<ui:composition template="../pages/initPage.xhtml">

<ui:define name="pageContent">

<!-- ToDo: add validations (input values correct and all present, example: filter without parameter) -->


    <h:panelGrid columns="1">
        <hr width="100%"/>
        <h1 style="width:100%">Database on Demand</h1>

        <table style="width:90%;">
            <tr>
                <td align="left">
                    Database on Demand development was supported by the <a href="http://www.bbsrc.ac.uk" target="blank">BBSRC</a> Tools and Resources Grant: BB/F016255/1.
                </td>
                <td align="right">
                     <a href="http://www.bbsrc.ac.uk" target="blank">
                         <img src="../images/bbsrc.gif" alt="BBSRC logo" style="border:none;"/>
                     </a>
                </td>
            </tr>
        </table>

        <br/>
        <b>Database on Demand</b> is a web-based database pre-processing tool that will generate custom FASTA formatted
        sequence databases according to a set of user-selectable criteria using the commonly used UniProt/SWISS-PROT
        and UniProt/TrEMBL databases as source.<br/>
        The source is freely available under the <a href="http://www.apache.org/licenses/LICENSE-2.0" target="blank">Apache licence 2.0</a>
        from its <a href="http://code.google.com/p/database-on-demand/" target="blank">Google code page</a>.
        For feedback and questions please send an email to <a href="mailto:pride-dod@ebi.ac.uk">pride-dod@ebi.ac.uk</a>. 
        <br/>
        <br/>
        <b>NOTE:</b> You can use the following regular expressions with the <a href="http://www.matrixscience.com" target="blank">MASCOT</a>
        search engine to retrieve the accession number and description from the FASTA headers in the result database. 
        For the accession number use <code>">[^|]*|\([^|]*\)|"</code> and for the description use <code>">[^|]*|[^|]*|\(.*\)"</code><br/>
        <br/>
        Database on Demand uses the <a target="blank" href="http://genesis.UGent.be/dbtoolkit">DBToolkit</a> software (PubMedID
        <a target="blank" href="http://www.ebi.ac.uk/citexplore/citationDetails.do?externalId=16030071&amp;dataSource=MED">16030071</a>) for its processing back-end.
        <br/>

        <tr:messages/>

        <!-- INPUT section -->
        <h2>INPUT: database selection, protein filtering, and protein maturation</h2>
        <tr:outputText escape="false" value="Select at least one database as source for your custom Database on Demand.
                                             For each source you will be able to add filters, for most of which you can
                                             also specify a filter parameter. When specifying multiple entries in a parameter, separate them using commas."/>
        <tr:panelBox id="inputBox" inlineStyle="width:100%"
                     partialTriggers="inputTable:filterTable:filterRemoveButton clearAllTrigger">
            <tr:panelBox inlineStyle="width:100%">
                <tr:panelHorizontalLayout>
                    <tr:selectOneChoice value="#{collectorBean.selectDB}" required="true"
                                        unselectedLabel="Choose a database">
                        <f:selectItems value="#{collectorBean.sourceDBSelectList}"/>
                    </tr:selectOneChoice>
                    <h:commandButton value="Add as source" actionListener="#{collectorBean.addSource}"/>
                </tr:panelHorizontalLayout>
            </tr:panelBox>
            <br/>
            <tr:table id="inputTable" rowSelection="none"
                      value="#{collectorBean.inputDBs}" var="inputDB"
                      rendered="#{collectorBean.inputDBsSize > 0}">
                <!--<tr:column headerText="Source type">-->
                    <!--<h:outputText value="#{inputDB.type}"/>-->
                <!--</tr:column>-->
                <tr:column headerText="Source">
                    <h:outputText value="#{inputDB.sourceDBName}"/>
                </tr:column>
                <tr:column headerText="Filters">
                    <h:outputText value="#{inputDB.filterSize}"/>
                </tr:column>
                <tr:column headerText=" optionally add a filter and filter parameter">
                    <tr:panelHorizontalLayout>
                        <tr:selectOneChoice id="filterSelector" autoSubmit="true" immediate="true"
                                            value="#{inputDB.selectedFilter}"
                                            unselectedLabel="Choose a filter"
                                            valueChangeListener="#{inputDB.renderFilterParamInput}">
                            <f:selectItems value="#{collectorBean.filterSelectList}"/>
                        </tr:selectOneChoice>
                        <tr:inputText value="#{inputDB.filterParam}" partialTriggers="filterSelector"
                                      columns="40" disabled="#{!inputDB.enableFilterParamInput}"/>
                        <tr:commandButton text="+" actionListener="#{inputDB.addFilter}"
                                          shortDesc="Add filter to the filter list for the current input database"/>
                    </tr:panelHorizontalLayout>
                </tr:column>
                <f:facet name="detailStamp">
                    <tr:panelGroupLayout>
                        <tr:table id="filterTable" rendered="#{not empty inputDB.filters}"
                                  value="#{inputDB.filters}"
                                  var="filterRow">
                            <tr:column>
                                <h:outputText value="#{filterRow.name}" />
                            </tr:column>
                            <tr:column>
                                <h:inputText value="#{filterRow.parameter}" size="40" readonly="true"/>
                            </tr:column>
                            <tr:column>
                                <tr:commandButton id="filterRemoveButton" text="-"
                                                  action="#{filterRow.action}" immediate="true"/>
                            </tr:column>
                        </tr:table>
                    </tr:panelGroupLayout>
                </f:facet>
            </tr:table>
        </tr:panelBox>

        <!-- PROCESSING section -->
        <h2>PROCESSING: enzymatic digest and ragging</h2>
        <tr:outputText escape="false" value="After selecting the input database(s), you can now optionally specify the desired processing steps
                                             by selecting one (or more) of the predefined enzymes or defining a regular
                                             expression based enzyme of your choice. If required, you can then choose to rag the resulting
                                             peptide database."/>
        <tr:panelBox id="processBox" partialTriggers="enzymeSelectorBox postEnzymeBox enzymeTable:enzymeRemoveButton clearAllTrigger"
                     inlineStyle="width:100%">
            <tr:panelBox id="enzymeSelectorBox" partialTriggers="enzymeSelector enzymeSelectorChoice"
                         inlineStyle="width:100%">
                <tr:panelHorizontalLayout>
                    <tr:selectOneRadio id="enzymeSelector" value="#{collectorBean.enzymeMethod}"
                                       required="yes" autoSubmit="true" layout="horizontal">
                        <f:selectItem itemLabel="select" itemValue="0" itemDescription="Use a pre-configured enzyme"/>
                        <f:selectItem itemLabel="regex" itemValue="1" itemDescription="Define your custom regular-expression driven enzyme"/>
                    </tr:selectOneRadio>
                    <tr:selectOneChoice id="enzymeSelectorChoice"
                                        value="#{collectorBean.selectedEnzyme}"
                                        unselectedLabel="Choose an enzyme"
                                        disabled="#{(collectorBean.enzymeMethod == 1)}"
                                        autoSubmit="true"
                                        valueChangeListener="#{collectorBean.emzymeSelectionChange}">
                        <f:selectItems value="#{collectorBean.enzymeSelectList}"/>
                    </tr:selectOneChoice>
                    <tr:inputText value="#{collectorBean.enzymeName}" columns="10" 
                                  shortDesc="The name of the enzyme"
                                  disabled="#{(collectorBean.enzymeMethod == 0)}"/>
                    <tr:inputText value="#{collectorBean.enzymeCleave}" columns="3"
                                  shortDesc="The definition of the cleavage site"
                                  disabled="#{(collectorBean.enzymeMethod == 0)}"/>
                    <tr:inputText value="#{collectorBean.enzymeRestrict}" columns="3"
                                  shortDesc="The restricting peptides (if any)"
                                  disabled="#{(collectorBean.enzymeMethod == 0)}"/>
                    <tr:inputNumberSpinbox value="#{collectorBean.enzymeMisCleav}" columns="1"
                                           shortDesc="The number of allowed miscleavages"
                                           minimum="0" maximum="10" stepSize="1">
                        <f:validateLongRange minimum="0" maximum="10"/>
                    </tr:inputNumberSpinbox>
                    <h:panelGrid width="170">
                        <tr:selectOneRadio value="#{collectorBean.enzymeCterm}" required="yes" layout="horizontal"
                                           disabled="#{(collectorBean.enzymeMethod == 0)}">
                            <f:selectItem itemLabel="Cterm" itemValue="0" itemDescription="C-terminal cleavage"/>
                            <f:selectItem itemLabel="Nterm" itemValue="1" itemDescription="N-terminal cleavage"/>
                        </tr:selectOneRadio>
                    </h:panelGrid>
                    <h:commandButton value="+" actionListener="#{collectorBean.addEnzyme}"/>
                </tr:panelHorizontalLayout>
            </tr:panelBox>
            <tr:panelGroupLayout partialTriggers="enzymeTable:enzymeRemoveButton">
                <tr:table id="enzymeTable" rendered="#{collectorBean.enzymeListSize > 0}"
                      value="#{collectorBean.enzymeList}"
                      var="enzymeRow" rowSelection="none">
                <tr:column headerText="enzyme name">
                    <h:outputText value="#{enzymeRow.name}"/>
                </tr:column>
                <tr:column headerText="cleavage site">
                    <h:outputText value="#{enzymeRow.cleavePattern}"/>
                </tr:column>
                <tr:column headerText="restrictors">
                    <h:outputText value="#{enzymeRow.restrictors}"/>
                </tr:column>
                <tr:column headerText="miscleavages">
                    <h:outputText value="#{enzymeRow.misCleavages}"/>
                </tr:column>
                <tr:column headerText="Cterm/Nterm">
                    <h:outputText value="#{enzymeRow.CNTermAsString}"/>
                </tr:column>
                <tr:column>
                    <tr:commandButton id="enzymeRemoveButton" text="-"
                                      action="#{enzymeRow.action}" immediate="true"
                                      actionListener="#{collectorBean.resetReportActionListener}"
                                      partialSubmit="true"/>
                </tr:column>
            </tr:table>
            </tr:panelGroupLayout>

            <tr:panelBox id="postEnzymeBox" partialTriggers="raggingSelector truncationSelector" inlineStyle="width:100%">
                <tr:panelHorizontalLayout>
                    <tr:selectBooleanCheckbox id="raggingSelector" value="#{collectorBean.ragging}"
                                              valueChangeListener="#{collectorBean.resetReportListener}"
                                              text="Ragging of database" selected="false" autoSubmit="true"/>
                    <tr:selectOneRadio value="#{collectorBean.raggingMethod}" layout="horizontal"
                                       rendered="#{collectorBean.ragging}">
                        <f:selectItem itemLabel="N-terminal" itemValue="1" itemDescription="Use N-terminal ragging"/>
                        <f:selectItem itemLabel="C-terminal" itemValue="0" itemDescription="Use C-terminal ragging"/>
                    </tr:selectOneRadio>
                    <tr:panelHorizontalLayout rendered="#{collectorBean.ragging}" valign="bottom">
                        <f:facet name="separator">
                            <tr:spacer width="10" height="1"/>
                          </f:facet>
                        <tr:selectBooleanCheckbox id="truncationSelector" value="#{collectorBean.truncate}"
                                                  valueChangeListener="#{collectorBean.resetReportListener}"
                                                  text="Truncate entries" selected="false" autoSubmit="true"/>
                        <tr:outputText value="to" rendered="#{collectorBean.truncate}"/>
                        <tr:inputNumberSpinbox value="#{collectorBean.raggingLimit}"
                                               minimum="10" maximum="1000" stepSize="10"
                                               rendered="#{collectorBean.truncate}">
                            <f:validateLongRange minimum="10" maximum="1000"/>
                        </tr:inputNumberSpinbox>
                        <tr:outputText value="N-terminal residues before ragging" rendered="#{collectorBean.truncate}"/>
                    </tr:panelHorizontalLayout>
                </tr:panelHorizontalLayout>
            </tr:panelBox>
        </tr:panelBox>
        <br/>

        <!-- OUTPUT section -->
        <h2>OUTPUT: post processing filters on peptide level</h2>
        <tr:outputText escape="false" value="As final processing step you can choose to restrict the results using
                                             either a powerful sequence filter or by specifying mass limits for the
                                             peptides."/>
        <tr:panelBox id="outputBox" partialTriggers="seqFilterSelector massLimitSelector massLimitStartSelector massLimitEndSelector clearAllTrigger"
                     inlineStyle="width:100%">
            <tr:panelHorizontalLayout>
                <tr:selectBooleanCheckbox id="seqFilterSelector" value="#{collectorBean.useSequenceFilter}"
                                          valueChangeListener="#{collectorBean.resetReportListener}"
                                          selected="false" text="Filter on sequence" autoSubmit="true"/>
                <tr:inputText value="#{collectorBean.sequenceFilter}" label="pattern:"
                              rendered="#{collectorBean.useSequenceFilter}" columns="50"/>
            </tr:panelHorizontalLayout>
            <tr:panelHorizontalLayout>
                <tr:selectBooleanCheckbox id="massLimitSelector" value="#{collectorBean.useMassLimit}"
                                          valueChangeListener="#{collectorBean.resetReportListener}"
                                          text="Use mass limits" selected="true" autoSubmit="true"/>
                <tr:inputNumberSpinbox id="massLimitStartSelector" value="#{collectorBean.massLimitStart}" 
                                       valueChangeListener="#{collectorBean.resetReportListener}"
                                       rendered="#{collectorBean.useMassLimit}" autoSubmit="true"
                                       label="from" minimum="100" maximum="10000" stepSize="10" columns="4">
                    <f:validateLongRange minimum="100" maximum="10000"/>
                </tr:inputNumberSpinbox>
                <tr:outputText value="Da" rendered="#{collectorBean.useMassLimit}"/>
                <tr:inputNumberSpinbox id="massLimitEndSelector" value="#{collectorBean.massLimitEnd}"
                                       rendered="#{collectorBean.useMassLimit}" autoSubmit="true"
                                       valueChangeListener="#{collectorBean.resetReportListener}"
                                       label="to" minimum="100" maximum="10000" stepSize="10" columns="4">
                    <f:validateLongRange minimum="#{collectorBean.massLimitStart + 10}" maximum="10000"/>
                </tr:inputNumberSpinbox>
                <tr:outputText value="Da" rendered="#{collectorBean.useMassLimit}"/>
            </tr:panelHorizontalLayout>
        </tr:panelBox>
        <br/>
        <br/>

        <!-- Summary section -->
        <h2>TASKS: description of the entire workflow</h2>
        <tr:message for="reportTrigger"/>
        <tr:panelBox id="submitBox" partialTriggers="reportTrigger clearAllTrigger inputBox processBox outputBox"
                     inlineStyle="width:100%">
            <tr:panelGroupLayout>
                <tr:panelHorizontalLayout>
                    <tr:commandButton id="reportTrigger" text="Generate workflow"
                                      actionListener="#{collectorBean.generateWorkflow}"/>
                    <tr:commandButton id="clearAllTrigger" text="Clear all" partialSubmit="true"
                                      immediate="true"
                                      actionListener="#{collectorBean.clearAll}"/>
                </tr:panelHorizontalLayout>
                <tr:panelGroupLayout partialTriggers="genAnyway">
                <tr:switcher facetName="#{collectorBean.reportView}" defaultFacet="default">
                    <f:facet name="default">
                        <br/>
                    </f:facet>
                    <f:facet name="ok">
                        <tr:panelGroupLayout>
                            <tr:outputFormatted value="#{collectorBean.formatedReport}"/>
                            <br/>
                            <br/>
                            <tr:panelGroupLayout>
                                <tr:outputText value="Since the creation of your database may take some time, we will inform you by
                                              email when your database is complete. "/>
                                <br/>
                                <tr:outputText value="Please provide your email address so
                                              we can send you a confirmation of your submitted request and
                                              a notice of the completion of your database together with a direct download link."/>
                                <tr:panelHorizontalLayout>
                                    <tr:inputText value="#{collectorBean.email}" columns="30" required="true"
                                                  requiredMessageDetail="A valid email address is required!"
                                                  shortDesc="Enter your email address" label="email:"/>
                                    <tr:commandButton id="submitScriptButton" text="Generate database"
                                                      onclick="alert('Your custom database will now be generated and you will receive a confirmation email shortly.');"
                                                      actionListener="#{collectorBean.submitScript}"/>
                                </tr:panelHorizontalLayout>
                            </tr:panelGroupLayout>
                        </tr:panelGroupLayout>
                    </f:facet>
                    <f:facet name="warn">
                        <tr:panelGroupLayout>
                            <tr:outputFormatted value="#{collectorBean.formatedReportMessage}"/>
                            <tr:commandButton id="genAnyway" text="Generate anyway" actionListener="#{collectorBean.generateWorkflowForward}" partialSubmit="true"/>
                        </tr:panelGroupLayout>
                    </f:facet>
                    <f:facet name="error">
                        <tr:panelGroupLayout>
                            <tr:outputFormatted value="#{collectorBean.formatedReportMessage}"/>
                        </tr:panelGroupLayout>
                    </f:facet>
                </tr:switcher>
                    </tr:panelGroupLayout>
            </tr:panelGroupLayout>
        </tr:panelBox>

    </h:panelGrid>


</ui:define>

</ui:composition>

</f:view>

</html>